<?php
	function custom_excerpt_length( $length ) {
		return 22;
	}
	add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
	
	function new_excerpt_more( $more ) {
		
		return '...<p><a class="btn btn-default btn-xs" href="'. get_permalink( get_the_ID() ) . '">Leer m&aacute;s</a></p>';

	}
	add_filter( 'excerpt_more', 'new_excerpt_more' );
	
	

/**
 * Register our sidebars and widgetized areas.
 *
 */
if ( function_exists('register_sidebar') ){
    register_sidebar(array(
        'name' => 'my_mega_menu',
        'before_widget' => '<div id="my-mega-menu-widget">',
        'after_widget' => '</div>',
        'before_title' => '',
        'after_title' => '',
));
}

/**
 * Modifica la pagina de usuarios
 *
 */

function modify_user_contact_methods( $user_contact ) {

	/* Add user contact methods */
//	$user_contact['skype'] = __( 'Skype Username' ); 
//	$user_contact['twitter'] = __( 'Twitter Username' ); 

	/* Remove user contact methods */
	unset( $user_contact['aim'] );
	unset( $user_contact['jabber'] );
	unset( $user_contact['yim'] );

	return $user_contact;
}
add_filter( 'user_contactmethods', 'modify_user_contact_methods' );


//remove the bio
function remove_plain_bio($buffer) {
    $titles = array('#<h3>'._x('About Yourself').'</h3>#','#<h3>'._x('About the user').'</h3>#');
    $buffer=preg_replace($titles,'<h3>'._x('Password').'</h3>',$buffer,1);
    $biotable='#<h3>'._x('Password').'</h3>.+?<table.+?/tr>#s';
    $buffer=preg_replace($biotable,'<h3>'._x('Password').'</h3> <table class="form-table">',$buffer,1);
    return $buffer;
}
function profile_admin_buffer_start() { ob_start("remove_plain_bio"); }
function profile_admin_buffer_end() { ob_end_flush(); }
add_action('admin_head', 'profile_admin_buffer_start');
add_action('admin_footer', 'profile_admin_buffer_end');





// removes the `profile.php` admin color scheme options
remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );

if ( ! function_exists( 'cor_remove_personal_options' ) ) {
  /**
   * Removes the leftover 'Visual Editor', 'Keyboard Shortcuts' and 'Toolbar' options.
   */
  function cor_remove_personal_options( $subject ) {
    $subject = preg_replace( '#<h3>Personal Options</h3>.+?/table>#s', '', $subject, 1 );
    return $subject;
  }

  function cor_profile_subject_start() {
    ob_start( 'cor_remove_personal_options' );
  }

  function cor_profile_subject_end() {
    ob_end_flush();
  }
}
add_action( 'admin_head-user-edit.php', 'cor_profile_subject_start' );
add_action( 'admin_footer-user-edit.php', 'cor_profile_subject_end' );


//----------------------------------------------------------//
//Redirecciona a los usuarios de la página de login a la Home
//----------------------------------------------------------//
function restrict_admin(){
	//si no es administrador, lo redirecciona la Home
	if ( ! current_user_can( 'manage_options' ) ) {
		wp_redirect( home_url() ); exit;
	}
}
add_action( 'admin_init', 'restrict_admin', 1 );


//-----------------------------------//
//----Filtro del Query del search----//
//-----------------------------------//
function pw_filter_query( $query ) {
	//Filtra contenidos a los suscriptores en el frontend
	if ( !is_admin() && !current_user_can('manage_options') && !is_page() ){
		$current_user = wp_get_current_user();
		$query->set('meta_key', 'meta_permisos_usuarios');
		$query->set('meta_value', array( 'todos', $current_user->user_login ));
	}
}

add_action('pre_get_posts', 'pw_filter_query', 9999);


//-----------------------------------//
//---------Disable admin bar---------//
//-----------------------------------//

add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {
if (!current_user_can('manage_options')) {
  show_admin_bar(false);
}
}



?>
